package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.common.util.DateUtils;
import com.movitech.mobile.cz.base.common.util.WebUtils;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormSendBid;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormSendBid;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormSendBidMapper;
import com.movitech.mobile.cz.base.purchase.mapper.ext.ExtWFlowFormSendBidMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormSendBidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 流程表单-发标 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormSendBidServiceImpl extends ServiceImpl<WFlowFormSendBidMapper, WFlowFormSendBid> implements WFlowFormSendBidService {

	@Autowired
	private ExtWFlowFormSendBidMapper extWFlowFormSendBidMapper;
	
	@Override
	public List<ExtWFlowFormSendBid> getSendBidListByFlowFormId(String flowFormId) {
		return extWFlowFormSendBidMapper.getSendBidListByFlowFormId(flowFormId);
	}


	@Override
	public Date setDowned(String formId, String supplierId) {
		Date now = DateUtils.getNow();
		WFlowFormSendBid where = new WFlowFormSendBid();
		where.setSupplierId(supplierId);
		where.setFlowFormId(formId);
		where.setDownloadOrNot(CommonConstants.NO_INTEGER);
		EntityWrapper entityWrapper = new EntityWrapper();
		entityWrapper.setEntity(where);

		WFlowFormSendBid wFlowFormSendBid = new WFlowFormSendBid();
		wFlowFormSendBid.setDownloadTime(now);
		wFlowFormSendBid.setDownloadIp(WebUtils.getIpAddr());
		wFlowFormSendBid.setDownloadOrNot(CommonConstants.YES_INTEGER);
		if(!update(wFlowFormSendBid,entityWrapper))
			now = null;
		return now;
	}

}
